<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('草稿箱列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>主题：</label>
                            <input type="text" name="noticeTheme"/>
                        </li>
                        <li>
                            <label>通知类型：</label>
                            <select name="noticeType" style="width: 80px;"
                                    th:with="type=${@dict.getType('sys_notice_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.itemText}"
                                        th:value="${dict.itemValue}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>时间段：</label>
                            <input type="text" class="time-input" placeholder="开始时间" name="noticeSendingTime_begin"/>
                            <span>-</span>
                            <input type="text" class="time-input" placeholder="结束时间" name="noticeSendingTime_end"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>


    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var removeFlag = [[${@permission.hasPermi('education:notice:remove')}]];
    var messageDatas = [[${@dict.getType('sys_notice_message')}]];
    var typeDatas = [[${@dict.getType('sys_notice_type')}]];
    var prefix = ctx + "education/notice";
    $(function () {
        var options = {
            url: prefix + "/toDraftList",
            modalName: "草稿箱",
            columns: [
                {
                    field: 'no',
                    title: '序号',
                    align: "center",
                    width: 40,
                    formatter: function (value, row, index) {
                        //获取每页显示的数量
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
                        //获取当前是第几页
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
                        //返回序号，注意index是从0开始的，所以要加上1
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    field: 'noticeId',
                    title: '通知编号',
                    visible:false
                },
                {
                    field: 'noticeTheme',
                    title: '主题'
                },
                {
                    field: 'noticeType',
                    title: '类型',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field: 'noticeMessage',
                    title: '是否发送短信',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(messageDatas, value);
                    }
                },
                {
                    field: 'noticeSendingTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="toDetail(\'' + row.noticeId + '\')"><i class="fa fa-search"></i>查看</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="sendCheck(\'' + row.noticeId + '\')"><i class="fa fa-envelope-o"></i>发送</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="toDraft(\'' + row.noticeId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }
                ]
        };
        $.table.init(options);
    });

    function toDetail(id) {
        var url = prefix + "/detail/" + id;
        var options = {
            title: "详细",
            width: 800 ,
            height: ($(window).height() - 50) ,
            url: url,
            skin: 'layui-layer-gray',
            btn: ['关闭'],
            yes: function (index, layero) {
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }

    function toDraft(id) {
        $.modal.confirm("确定将该条通知放入废件箱吗？",function () {
            var config = {
                url: prefix + "/toDelete",
                type: "post",
                dataType: "json",
                data: {"id":id},
                beforeSend: function (request) {
                    request.setRequestHeader("X-Access-Token", storage.get("token"));
                },
                success: function(result) {
                    $.operate.saveSuccess(result);
                }
            };
            $.ajax(config)
        });
    }

    function sendCheck(id) {
        var url = prefix + "/sendCheck/" + id;
        $.modal.openTab("发通知",url)
    }
</script>
</body>
</html>
